﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data;
using MINERP.MODEL.PhotoRindGrid;
using Microsoft.Practices.EnterpriseLibrary.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.Common;

namespace MINERP.DAL.PhotoRindGrid
{
    public class OrderInfoDAL
    {
        public PhotoGridOrderHeadInfo GetOrderHeadInfoById(int orderProductId)
        {
            PhotoGridOrderHeadInfo headInfo = new PhotoGridOrderHeadInfo();
            Database db = null;
            try
            {
                db = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = db.GetStoredProcCommand("proc_GetOrderHeadInfoById");
                db.AddInParameter(dbCommand, "@orderProductid", DbType.Int32, orderProductId);

                using (IDataReader dr=db.ExecuteReader(dbCommand))
                {
                    while (dr.Read())
                    {
                        headInfo.orderBagCode = dr.GetString(0);
                        headInfo.orderProductid = orderProductId;
                        headInfo.orderInfoCode = "2" + string.Format("{0:d9}", orderProductId);
                        headInfo.orderProductName = dr.GetString(1);
                        headInfo.shopName = dr.GetString(2);
                        headInfo.ctmName = dr.GetString(3);
                    }
                }
            }
            catch (Exception)
            {

                throw;
            }

            return headInfo;
        }

        public string GetShopName(int orderProductid)
        {
            CommonDAL.OrderInfoDAL _dal = new MINERP.DAL.CommonDAL.OrderInfoDAL();
            orderInfo oi = _dal.GetOneById(orderProductid);
            if (!oi.Tb_OrderBagReference.IsLoaded)
            {

                oi.Tb_OrderBagReference.Load();
            }
          
                oi.Tb_OrderBag.ShopReference.Load();
           
            return oi.Tb_OrderBag.Shop.shopName;
        }
       
    }
}
